package slash.collision;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Shape;

import slash.entities.AbstractEntity;
import slash.util.IRenderable;

public class CollisionMask implements IRenderable,Collidable{
	private Shape mask;
	private AbstractEntity owner;
	
	private float x = 0;
	private float y = 0;
	
	public CollisionMask(Shape shape, AbstractEntity owner) {
		this.mask = shape;
		this.owner = owner;
	}
	
	public void setOffSet(float f, float g){
		this.x = f;
		this.y = g;
	}
	
	private Shape getMaskShape(){
		return mask;
	}

	@Override
	public void update(GameContainer container, int time) {
		/* sets */
		mask.setCenterX(owner.getCenterX());
		mask.setCenterY(owner.getCenterY());
		//mask.setCenterX(owner.getPosX());
		//mask.setCenterY(owner.getPosY());
	}

	@Override
	public void render(Graphics g){
		g.setColor(Color.red);
		g.draw(mask);
	}

	/**
	 * Returns whether the mask has collided with another entity's mask
	 * @param entity
	 * @return
	 */
	public boolean collidesWith(AbstractEntity entity){
		Shape a = this.mask;// shape of mask
		Shape b = entity.getCollisionMask().getMaskShape();// shape of mask of colliding entity
		/* checks to see if the two shapes intersect */
		if(a.intersects(b)){
			return true;
		} else return false;
	}
}
